package com.example.lenovo.demo.presenter.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.lenovo.demo.R;
import com.example.lenovo.demo.model.databean.StrategyBean;

import java.util.List;

/**
 * Created by Lenovo on 2017/1/15.
 */

public class StrategyChildFg_Rv_item_RvAdapter extends RecyclerView.Adapter<StrategyChildFg_Rv_item_RvAdapter.ViewHolder> {
    private List<StrategyBean.PagesBean.ChildrenBean.SectionsBean> data;
    private Context context;

    public StrategyChildFg_Rv_item_RvAdapter(List<StrategyBean.PagesBean.ChildrenBean.SectionsBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public StrategyChildFg_Rv_item_RvAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.strategychildfg_rv_item_rvadapter_item,parent,false));
    }

    @Override
    public void onBindViewHolder(StrategyChildFg_Rv_item_RvAdapter.ViewHolder holder, int position) {
        StrategyBean.PagesBean.ChildrenBean.SectionsBean sectionsBean =data.get(position);
        holder.title.setText(sectionsBean.getTitle());
        holder.content.setText(sectionsBean.getDescription());
        StrategyChildRv_Rvitem_RvImgAdapter adapter=new StrategyChildRv_Rvitem_RvImgAdapter(sectionsBean.getPhotos(),context);
//        Log.e("msg",sectionsBean.getPhotos().size()+"==?"+sectionsBean.getPhotos().get(0).getImage_url());
        LinearLayoutManager manager=new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false);
        manager.setAutoMeasureEnabled(true);
        holder.recyclerView.setLayoutManager(manager);
        holder.recyclerView.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView title,content;
        RecyclerView recyclerView;
        public ViewHolder(View itemView) {
            super(itemView);
            title= (TextView) itemView.findViewById(R.id.strategy_rvitem_rvadapter_item_title);
            content= (TextView) itemView.findViewById(R.id.strategy_rvitem_rvadapter_item_content);
            recyclerView= (RecyclerView) itemView.findViewById(R.id.strategy_rvitem_rvadapter_item_rv);
        }
    }
}
